﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RssNewsList.ascx.cs" Inherits="admin_webparts_Plug_ins_RssNews_RssNewsList" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %>
<%@ Import Namespace="NTTHAO.Web.BL.Rss" %>
<%
    string backUrl = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&item=" + Request.QueryString["item"];
    string bUrl = backUrl + "&g=" + Request.QueryString["g"];
    bool isAdmin = Context.User.Identity.Name.Equals("admin", StringComparison.OrdinalIgnoreCase);
    int langID = LanguageUtility.GetLanguageID();
    int siteID = WebGlobal.GetSite().ID;
    
%>
<script type="text/javascript">
    function confirmDelete() {
        var msg = '<%=LanguageUtility.GetLanguageText("CONFIRM_DELETE", Session).Replace(Environment.NewLine, "<br />")%>';
        return confirm(msg.replace(/<br \/>/gi, "\r\n").replace(/<br\/>/gi, "\r\n"));
    }
    function removeContent(id) {
        var url = '<%=_PageUrl %>&action=removenews&id=' + id + '&ReturnUrl=<%=Server.UrlEncode(Request.Url.ToString()) %>';
        location.href = url;
        return false;
    }
    function deleteContent(id) {
        if (!confirmDelete()) return;
        var url = '<%=_PageUrl %>&action=deletenews&id=' + id + '&ReturnUrl=<%=Server.UrlEncode(Request.Url.ToString()) %>';
        location.href = url;
        return false;
    }
//    YAHOO.util.Event.onDOMReady(function() {
//        var remLinks = YAHOO.util.Dom.getElementsByClassName('inactivebn', 'a');
//        for(var i = 0; i < remLinks.length; i++) {
//            remLinks[i];
//        }
//        var delLinks = YAHOO.util.Dom.getElementsByClassName('deletebn', 'a');
//    });
    
    function reload(that) {
        that.className = 'icon refreshbtn2';
        
        var callback = {
            success: function(o) {
                that.className = 'icon refreshbtn';
                /*
                var href = that.href;
                if (href.indexOf('&action') >= 0) {
                    href = href.substr(0, href.indexOf('&action'));
                }
                location.href = href; */
            },
            failure: function(o) {alert('An error occurred while loading RSS.');}
        };
        YAHOO.util.Connect.asyncRequest('GET', that.href, callback, null);
        
        return false;
    }
</script>
<div class="tip" style="position: relative;">
	<h1 style="left: 0px; position: relative;">Quản lý tin tức RSS</h1>
	<div style="display: block; width: 32px; height: 32px; float: right; position: absolute; top: 5px; right: 5px;"><a title="Click vào đây để quay lại." href="<%=backUrl %>"><img alt="Back" src="resources/images/Back.png" /></a></div>
</div>
<style type="text/css">
.stairs .stair .step p a { display: block; }
.stairs .stair .step p.selected { background: #3260F4; font-weight: bold; }
.stairs .stair .step p.selected a { color: #fff; }
</style>
<div class="oh">
    <div style="float: left; width: 240px;">
        <div class="tip" style="margin-bottom: 0px; padding: 0px;">
            <div class="stairs oh">
                <div class="step b" style="border-left: none; border-bottom: dashed 1px #89D;">
                    <p><%=_Group.Name %></p>
                    <ul class="icon" style="width: 28px;">
                        <li><a title="Update" href="<%=bUrl+"&m=0" %>&action=updatenews" class="icon refreshbtn">&nbsp</a></li>
                    </ul>
                </div>
                <div class="stair"><%
    try
    {
        RssGroupTree tree = RssPageGroup.GetTree(_Group.ID);
        RssMenuNode node = tree.Node;
        while (node != null)
        {
            if (node.Menu.ID > 0)
            {
%>
                    <div class="step">
                        <p <%=node.Menu.ID == this._MenuID ? " class=\"selected\"" : "" %>><a href="<%=bUrl+"&m=" + node.Menu.ID.ToString() %>"><%=node.Menu.Text %></a></p>
                        <ul class="icon" style="width: 28px;">
                            <li><a title="Update" href="<%=bUrl+"&m=" + node.Menu.ID.ToString() %>&action=updatenews" class="icon refreshbtn" onclick="return reload(this);">&nbsp</a></li>
                        </ul>
                    </div> <%
            }

            if (node.Children != null)
            {
                if (node.Menu.ID > 0)
                {
%>
                    <div class="step">
                        <div class="stair"><%
                }
                node = node.Children[0];
            }
            else if (node.NextNode != null)
            {
                node = node.NextNode;
            }
            else
            {
                bool next = false;
                while (!next && node != null)
                {
                    if (node.Parent != null && node.Parent.Menu.ID > 0)
                    {
%>
                        </div>
                    </div> <%
                    }
                    node = node.Parent;
                    if (node != null && node.NextNode != null)
                    {
                        node = node.NextNode;
                        next = true;
                    }
                }
            }
        }
            
    }
    catch { }
%>
                </div>
            </div>
        </div>
    </div>
    <div style="margin-left: 250px;" class="border">
        <div style="padding: 5px; overflow: hidden;">
<div class="border" style="padding: 5px;">
    <div style="overflow: hidden;font-weight: bold; padding-left: 2px;">
        <span><%=LanguageUtility.GetLanguageText("TOTAL") %>: <span style="color: #E76300;"><%=_TotalItem %></span> <%=LanguageUtility.GetLanguageText("ITEMS") %>.</span> <%if (_TotalItem > 1) { %>
        <span><%=LanguageUtility.GetLanguageText("VIEW")%>: <span style="color: #E76300;"><%=(_PageNo - 1) * PAGE_SIZE + 1%> - <%= ((_PageNo - 1) * PAGE_SIZE + (_List == null ? 0 : _List.Rows.Count))%></span></span>
        <%} %>
    </div>
<%if (_PageCount > 1) { %>
    <div style="overflow: hidden; padding-top: 10px;">
        <div class="boxPaging">
            <div class="pagenum f-left">
                <ul>
                    <li><a class="first" href="<%=this._PageUrl + "&page=1" %>">|&lt;&nbsp;Đầu</a></li>
                    <li><a class="pre" href="<%=this._PageUrl + "&page=" + (this._PageNo <= 1 ? 1 : (this._PageNo - 1)) %>">&lt;</a></li>
                    <%
                        int startPage = _PageNo - 4;
                        if (startPage > _PageCount - 9)
                        {
                            startPage = _PageCount - 9;
                        }
                        if (startPage < 1)
                        {
                            startPage = 1;
                        }
                        for (int i = startPage; i <= _PageCount && i < (startPage + 10); i++)
                        {
                    %>
                    <li <%=(i == _PageNo ? "class=\"selected\"" : "") %>><a href="<%=this._PageUrl + "&page=" + i.ToString() %>"><%=i %></a></li>
                    <%   
                        }
                    %>
                    <li><a class="next" href="<%=this._PageUrl + "&page=" + (this._PageNo >= this._PageCount ? this._PageCount : (this._PageNo + 1)) %>">&gt;</a></li>
                    <li><a class="last" href="<%=this._PageUrl + "&page=" + this._PageCount.ToString() %>">Cuối&nbsp;&gt;|</a></li>
                </ul>
            </div>
        </div>
    </div>
<%} %>
</div>

<% int startNum = (_PageNo - 1) * PAGE_SIZE; 
if (_List != null) {
%>
<table border="1" cellpadding="0" cellspacing="0" class="grid" id="tbGrid" style="margin-top: 10px;">
    <tr>
        <th width="32px">#</th>
        <th>Tin tức</th>
        <th width="28px">&nbsp;</th>
    </tr>
    <%if (this._List != null) for (int i = 0; i < this._List.Rows.Count; i++) 
      {
          System.Data.DataRow row = this._List.Rows[i];
          string id = row[RssContent.ID__COLUMN_NAME].ToString();
          int rssSiteID = (int)row["RssSiteID"];
          string title = row[RssContent.TITLE__COLUMN_NAME].ToString();
          string desc = row[RssContent.DESCRIPTION__COLUMN_NAME].ToString();
          string image = row[RssContent.IMAGE__COLUMN_NAME].ToString();
          string link = row[RssContent.LINK__COLUMN_NAME].ToString();
          DateTime pubDate = ((DateTime)row[RssContent.PUBLICTIME__COLUMN_NAME]);
          RssSite site = RssSite.GetSite(rssSiteID);
          string siteName = site.SiteName;
          string siteDomain = site.SiteDomain;
          string siteIcon = site.ShortcutIcon;
    %>
    <tr class="<%=(i%2==1?"even":"odd") %>">
        <td align="center"><%=i + 1 + startNum %></td>
        <td>
            <div class="oh" style="padding: 3px;">
                <%if (image != string.Empty) { %>
                <a target="_blank" href="<%=link %>"><img alt="" style="float: left; max-width: 120px; margin: 0px 10px 0px 0px;" src="<%=image %>" /></a>
                <%} %>
                <p style="margin-top: 5px;"><b><a target="_blank" href="<%=link %>"><%=title %></a></b></p>
                <p style="font-size: 10px;"><a class="icon-back" style="background-image:url(<%=siteIcon %>)" href="<%=siteDomain %>" target="_blank"><%=siteName %></a> - <%=pubDate.Year == 9999 ? "" : ("<span style=\"color: #87C631;\">" + pubDate.ToString("yyyy/MM/dd HH:mm") + "</span>")%></p>
                <p style="margin-top: 5px;"><%=desc%></p>
            </div>
        </td>
        <td align="left">
            <ul class="icon" style="width: 56px;">
                <li><a title="Xóa tạm thời" href="<%=this._PageUrl %>&id=<%=id %>&action=removenews" class="icon inactivebn" onclick="return removeContent(<%=id %>);">&nbsp</a></li>
                <li><a title="Xóa vĩnh viễn" href="<%=this._PageUrl %>&id=<%=id %>&action=deletenews" class="icon deletebn" onclick="return deleteContent(<%=id %>);">&nbsp</a></li>
            </ul>
        </td>
    </tr>
    <%} %>
</table>
<%} %>
<%if(_List != null) { %>
<div class="border" style="padding: 5px; margin-top: 10px;">
    <div style="overflow: hidden;font-weight: bold; padding-left: 2px;">
        <span><%=LanguageUtility.GetLanguageText("TOTAL") %>: <span style="color: #E76300;"><%=_TotalItem %></span> <%=LanguageUtility.GetLanguageText("ITEMS") %>.</span> <%if (_TotalItem > 1) { %>
        <span><%=LanguageUtility.GetLanguageText("VIEW")%>: <span style="color: #E76300;"><%=(_PageNo - 1) * PAGE_SIZE + 1%> - <%= ((_PageNo - 1) * PAGE_SIZE + (_List == null ? 0 : _List.Rows.Count))%></span></span>
        <%} %>
    </div>
<%if (_PageCount > 1) { %>
    <div style="overflow: hidden; padding-top: 10px;">
        <div class="boxPaging">
            <div class="pagenum f-left">
                <ul>
                    <li><a class="first" href="<%=this._PageUrl + "&page=1" %>">|&lt;&nbsp;Đầu</a></li>
                    <li><a class="pre" href="<%=this._PageUrl + "&page=" + (this._PageNo <= 1 ? 1 : (this._PageNo - 1)) %>">&lt;</a></li>
                    <%
                        int startPage = _PageNo - 4;
                        if (startPage > _PageCount - 9)
                        {
                            startPage = _PageCount - 9;
                        }
                        if (startPage < 1)
                        {
                            startPage = 1;
                        }
                        for (int i = startPage; i <= _PageCount && i < (startPage + 10); i++)
                        {
                    %>
                    <li <%=(i == _PageNo ? "class=\"selected\"" : "") %>><a href="<%=this._PageUrl + "&page=" + i.ToString() %>"><%=i %></a></li>
                    <%   
                        }
                    %>
                    <li><a class="next" href="<%=this._PageUrl + "&page=" + (this._PageNo >= this._PageCount ? this._PageCount : (this._PageNo + 1)) %>">&gt;</a></li>
                    <li><a class="last" href="<%=this._PageUrl + "&page=" + this._PageCount.ToString() %>">Cuối&nbsp;&gt;|</a></li>
                </ul>
            </div>
        </div>
    </div>
<%} %>
</div>
<%} %>
        </div>
        <div class="clearfix"></div>
    </div>
</div>
